package cn.zz.veggie.model.query;

import java.util.Objects;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import cn.zz.comm.core.types.query.CommQuery;
import cn.zz.comm.mybaits.types.BaseQuery;
import cn.zz.veggie.model.domain.Purchase;
import lombok.Getter;
import lombok.Setter;

/**
 * 采购统计表(Purchase)查询器
 *
 * @author zhongq
 * @since 2024-06-03 23:40:02
 */
@Getter
@Setter
public class PurchaseQuery extends CommQuery<Integer> implements BaseQuery<Purchase> {

	public Long statTime;
	public Long statTimeStart;
	public Long statTimeEnd;

	public static PurchaseQuery of(Long statTime) {
		final PurchaseQuery query = new PurchaseQuery();
		query.statTime = statTime;
		return query;
	}

	@Override
	public void injectCondition(LambdaQueryWrapper<Purchase> queryWrapper) {
		queryWrapper.eq(Objects.nonNull(id), Purchase::getId, id);
		queryWrapper.in(Objects.nonNull(ids), Purchase::getId, ids);
		queryWrapper.eq(Objects.nonNull(statTime), Purchase::getStatTime, statTime);
		queryWrapper.ge(Objects.nonNull(statTimeStart), Purchase::getStatTime, statTimeStart);
		queryWrapper.lt(Objects.nonNull(statTimeEnd), Purchase::getStatTime, statTimeEnd);
	}

	@Override
	public void injectOrderBy(Page<Purchase> page) {
		page.addOrder(OrderItem.desc("stat_time"));
	}
}